<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
<script>
    $(function () {
        var currentPage = 1;//当前页,默认首页为1
        var pages;//存储总页数的容器
        var travelData = [];//存储分页数据的容器
        var loading = false;//标志,用来解决尾页多次触发查询的问题
        //抽取分页查询
        function query() {
            //如果正在查询,就结束
            if (loading) {
                return;
            }
            //不在查询就查询,并修改标志为正在查询
            loading = true;
            //获取所有已发布游记数据
            $.get("/travels",{currentPage:currentPage},function (data) {
                console.log(data);
                $.merge(travelData,data.list);//将每次查询的分页数据合并
                var json = {list:travelData};//将数据封装成有list属性的对象
                pages = data.pages;//获取总分页数
                //对页面进行数据渲染
                $(".container").renderValues(json,{
                    getUrl:function (item,value) {//参数1:获取贴有 render-fun="getUrl"属性的元素;参数2:可获取的参数
                        var url = $(item).data("href");
                        $(item).attr("href",url+value);//将id拼接在资源名后
                    },
                    getAuthorUrl:function (item,value) {//参数1:获取贴有 render-fun="getUrl"属性的元素;参数2:可获取的参数
                        var url = $(item).data("href");
                        console.log(url);
                        console.log(value);
                        $(item).attr("href",url+value);//将id拼接在资源名后
                    }
                });
                currentPage++;
                //执行完查询之后,修改标志为不查询
                loading = false;
            })
        }
        //查询首页
        query();
        //给屏幕绑定滑动事件
        $(window).scroll(function () {
            //屏幕滚动触发分页查询(当屏幕的总高度加上溢出的总长度大于等于查询过来页面的长度时)
            if ($(window).height() + $(document).scrollTop() >= $(document).height()) {
                if (currentPage <= pages) {
                    query();//第二次查询
                }else {
                    //提醒,没有更多数据了
                    $(document).dialog({
                        type: 'notice',
                        infoText: '没有更多数据了',
                        autoClose: 1500,
                        position: 'bottom'  // center: 居中; bottom: 底部
                    });
                }
            }
        })
        //
    })
</script>
</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div ><div class="carousel-item active">
                <div class="border commend">
                    <a href="travelContent.html">
                        <img src="/upload/acd22908-8780-4e81-8468-8dac6724b8d1.jpeg" width="100%" height="200px">
                        <h1 > 骨灰级成都吃货地图</h1>
                        <small >成都成都</small>
                    </a>
                </div>
            </div></div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels" render-loop="list">
        <div class="row detail">
            <div class="col">
                <a data-href="travelContent.html?id=" render-fun="getUrl" render-key="list.id">
                    <h4 render-html="list.title"></h4>
                </a>
                <p>
                    <a data-href="userProfiles.html?id=" render-fun="getAuthorUrl" render-key="list.author.id">
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName"></span> </a> 在
                    <span class="addr" render-html="list.place.name"></span>

                </p>
                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span>0</span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span>0</span>
                </p>
            </div>
            <div class="col bigimg">
                <a data-href="travelContent.html?id=" render-fun="getUrl" render-key="list.id">
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
    </div>
</div>



</body>

</html>